home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / example / main.c < prev    next >
C/C++ Source or Header  |  1992-09-04  |  2KB  |  99 lines

  1. /*
  2.  *      file:   main.c:   
  3.  *      author: Charlie Gunn & Tamara Munzner
  4.  *      date:   September 1, 1992
  5.  *      
  6.  *      simple example of geomview external module and
  7.  *    OOGL graphics library routines.
  8.  *
  9.  *      The main program continually computes a function on a mesh of
  10.  *      (x,y) pairs.  The updated mesh is printed to stdout. When this
  11.  *    program is invoked as a geomview external module, pipes are hooked
  12.  *     up 
  13.  */
  14.  
  15. #include <math.h>
  16. #include <stdio.h>
  17. #include "forms.h"
  18. #include "panel.h"
  19. #include "ooglutil.h"
  20.  
  21. float dt;
  22.  
  23.  
  24. /* replace this with your favorite function */
  25. float
  26. myfunc(x,y,t)
  27.      float x,y,t;
  28. {
  29.         float r;
  30.         r = sqrt(x*x+y*y) + .000001;
  31.         return(sin(r + t)*sqrt(r));
  32. }
  33.  
  34. main(argc, argv)        
  35.      char **argv;
  36. {
  37.         int xdim, ydim, i, j;
  38.         float xmin, xmax, ymin, ymax, xsize, ysize, dx, dy, x, y, t, zscale;
  39.         float *data;
  40.         
  41.         xdim = 24;
  42.         ydim = 24;
  43.         xmin = -5;
  44.         xmax = 5;
  45.         ymin = -5;
  46.         ymax = 5;
  47.         zscale = 2.0;
  48.  
  49.     dt = .1; /* initial velocity */
  50.  
  51.     /* geomview communications setup. */
  52.  
  53.         Begin_OOGL();
  54.  
  55.     /* If we don't foreground then the process forks and dies
  56.        as soon as we do graphics. This is bad.
  57.      */
  58.  
  59.     foreground();
  60.  
  61.     /* This routine is defined in the code generated by 
  62.        the forms designer.
  63.      */
  64.  
  65.         create_the_forms();
  66.  
  67.     /* We set the slider and display the form. */
  68.  
  69.     fl_set_slider_bounds(VelocitySlider, 0.0, 1.0);
  70.     fl_set_slider_value(VelocitySlider, dt);
  71.     fl_show_form(Example, FL_PLACE_SIZE, TRUE, "Example");
  72.  
  73.         
  74.         xsize = xmax-xmin;
  75.         ysize = ymax-ymin;
  76.         dx = xsize/(xdim-1);
  77.         dy = ysize/(ydim-1);
  78.         
  79.         data = (float *) OOGLNewN(float, xdim * ydim);
  80.         for (t=0; ; t += dt)
  81.         {
  82.             /* Let forms library do its thing. */
  83.             fl_check_forms();
  84.  
  85.                 /* compute mesh of some function value */
  86.                 for (j=0, y = -ysize/2; j<ydim; ++j, y += dy)
  87.                 {
  88.                         for (i=0, x = -xsize/2; i<xdim; ++i, x += dx)
  89.                         {
  90.                                 data[j*xdim + i] = myfunc(x,y,t);
  91.                         }
  92.                 }
  93.                 
  94.                 /* geomview communications update */
  95.                 UpdateOOGL(xdim, ydim, zscale, data);
  96.         }
  97.     
  98. }
  99.